#include <mcp/version.h>

#include <sstream>
#include <algorithm>

namespace mcp {

std::string Version::get_version_string() {
    std::ostringstream ss;
    ss << MAJOR << "." << MINOR << "." << PATCH;
    return ss.str();
}

std::string Version::get_version_info() {
    std::ostringstream ss;
    ss << "MCP C++ SDK v" << get_version_string();

    // Include commit hash if not default
    if (std::string(COMMIT_HASH) != "development") {
        ss << " (" << COMMIT_HASH << ")";
    }

    return ss.str();
}

bool Version::is_compatible(int major, int minor, int patch) {
    // Major version must match exactly
    if (major != MAJOR) {
        return false;
    }

    // Minor version must be less than or equal to current
    if (minor > MINOR) {
        return false;
    }

    // If minor version matches exactly, patch must be less than or equal
    if (minor == MINOR && patch > PATCH) {
        return false;
    }

    return true;
}

} // namespace mcp